package dy.com.part1.chapter3;

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class ThreadSleep {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getContextClassLoader());
        System.out.println("main: "+Thread.currentThread().getPriority()+" "+Thread.currentThread().getThreadGroup().getMaxPriority());
    Thread t1 = new Thread(()->{
        long startTime = System.currentTimeMillis();

        System.out.println(Thread.currentThread().getName()+"开始休眠:"+new Date());
        sleep(2);
        System.out.println(Thread.currentThread().getName()+"休眠结束:"+new Date()+"，"+"耗时："+(System.currentTimeMillis()-startTime));
    });
    t1.setPriority(2);
    t1.start();
        System.out.println(t1.getPriority());

        long startTime = System.currentTimeMillis();
        System.out.println(Thread.currentThread().getName()+"开始休眠:"+new Date());
        sleep(3);
        System.out.println(Thread.currentThread().getName()+"休眠结束:"+new Date()+"，"+"耗时："+(System.currentTimeMillis()-startTime));

    }
    public static void sleep(int seconds)  {
        try{
            TimeUnit.SECONDS.sleep(seconds);
        }
        catch (InterruptedException e){
            e.printStackTrace();
        }

    }

}
